package org.alwayssuper.protocol.commons.transform.realtimev2025.enums;

/**
 * 最高报警等级枚举 (报警数据 0x06)
 * 基于 GB/T 32960.3-2025 标准
 * @author alwaysSuper
 */
public enum AlarmLevel {
    NO_FAULT(0, "无故障"),
    LEVEL_1_FAULT(1, "1级故障"),
    LEVEL_2_FAULT(2, "2级故障"),
    LEVEL_3_FAULT(3, "3级故障"),
    THERMAL_EVENT_FAULT(4, "热事件故障"),
    ABNORMAL(0xFE, "异常"),
    INVALID(0xFF, "无效");

    private final int code;
    private final String description;

    AlarmLevel(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static AlarmLevel fromCode(int code) {
        for (AlarmLevel level : values()) {
            if (level.code == code) {
                return level;
            }
        }
        return INVALID;
    }

    /**
     * 检查是否为严重故障 (3级、4级)
     * @return true:严重故障 false:非严重故障
     */
    public boolean isSevereFault() {
        return this == LEVEL_3_FAULT || this == THERMAL_EVENT_FAULT;
    }

    /**
     * 获取故障等级颜色代码 (用于显示)
     * @return 颜色代码
     */
    public String getColorCode() {
        switch (this) {
            case NO_FAULT:
                return "GREEN";
            case LEVEL_1_FAULT:
                return "YELLOW";
            case LEVEL_2_FAULT:
                return "ORANGE";
            case LEVEL_3_FAULT:
                return "RED";
            case THERMAL_EVENT_FAULT:
                return "DARK_RED";
            default:
                return "GRAY";
        }
    }

    @Override
    public String toString() {
        return String.format("AlarmLevel{code=%d, description='%s'}", code, description);
    }
}